package com.superatom.designpattern.singleton.registersingleton;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 注册式单例-容器型
 */
public class BeanFactory {

    public static Map<String, Object> registerMap = new ConcurrentHashMap<String, Object>();

    public static Object getBean(String classname){
        if (registerMap.containsKey(classname)){
            return registerMap.get(classname);
        }else{
            Object bean = null;
            try {
                Class clazz = Class.forName(classname);
                bean = clazz.newInstance();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return bean;
        }
    }
}
